#include<stdio.h>
long long n,sumTotal=0;
long long maxSum1,maxSum2,maxSum;
long long a[5];
void input(void){
    FILE *fp=fopen("EXPR.INP","r");
    long long temp=0;
    fscanf(fp,"%lld",&n);
    int i=0;
    fscanf(fp,"%lld%lld%lld",&a[1],&a[2],&a[3]);
    if(a[1]*a[2]>a[2]*a[3]){
        maxSum1=a[1]*a[2]-a[1]-a[2];
        maxSum2=a[2]*a[3]-a[2]-a[3];
    }else{
        maxSum2=a[1]*a[2]-a[1]-a[2];
        maxSum1=a[2]*a[3]-a[2]-a[3];
    }  
    sumTotal=a[1]+a[2]+a[3];
    maxSum=a[1]*a[2]*a[3]-a[1]-a[2]-a[3];
    for(int ii=4;ii<=n;ii++){
        fscanf(fp,"%lld",&a[4]);
        sumTotal+=a[4];
        
        temp=a[4]*a[3]*a[2]-a[4]-a[3]-a[2];
        if(temp>maxSum)maxSum=temp;
        
        temp=a[4]*a[3]-a[4]-a[3];
        if(temp>maxSum1){
               maxSum2=maxSum1;
               maxSum1=temp;
        }else if(temp>maxSum2)maxSum2=temp;
        a[2]=a[3];
        a[3]=a[4];
    }
    fclose(fp);
}
void output(long long result){
    FILE *fp=fopen("EXPR.OUT","w");
    fprintf(fp,"%lld",result);
    fclose(fp);
}
int main(){
    input();
    output(maxSum1+maxSum2>maxSum?sumTotal+maxSum1+maxSum2:sumTotal+maxSum);
    return 0;
}
        
        
